﻿using System.Diagnostics;
using Fabrication;
using Fabrication.Tests;
using Fabrication.Tests.TestClasses;
using NUnit.Framework;

namespace Fabricator.SpeedTests
{
    [TestFixture]
    public class fabricator
    {
        [TestCase(1, 1)]
        [TestCase(100, 1)]
        [TestCase(1000, 1)]
        [TestCase(10000, 1)]
        [TestCase(100000, 2)]
        //[TestCase(1000000, 10)]
        public void should_quickly_generate_simple_items(int numberOfItems, int maxSeconds)
        {
            var sw = Stopwatch.StartNew();
            new FabricationScope().Generate<SinglePropertyClass<string>>(numberOfItems);
            sw.Stop();
            Assert.That(sw.Elapsed.Seconds, Is.LessThan(maxSeconds), string.Format("Generating {0} simple items took {1}", numberOfItems, sw.Elapsed));
        }

        [TestCase(1, 1)]
        [TestCase(100, 1)]
        [TestCase(1000, 1)]
        [TestCase(10000, 3)]
        //[TestCase(100000, 20)]
        //[TestCase(1000000, 180)]
        public void should_quickly_generate_complex_items(int numberOfItems, int maxSeconds)
        {
            var sw = Stopwatch.StartNew();
            new FabricationScope().Generate<AllRulePropertyBag>(numberOfItems);
            sw.Stop();
            Assert.That(sw.Elapsed.Seconds, Is.LessThan(maxSeconds), string.Format("Generating {0} complex items took {1}", numberOfItems, sw.Elapsed));
        }


        [TestCase(1, 1)]
        [TestCase(100, 1)]
        [TestCase(1000, 1)]
        [TestCase(100000, 3)]
        //[TestCase(100000, 20)]
        //[TestCase(1000000, 180)]
        public void should_quickly_generate_items_with_expressions(int numberOfItems, int maxSeconds)
        {
            var sw = Stopwatch.StartNew();
            new FabricationScope().Setup<AlpabeticalProperties>()
                .For(x => x.B).Use(x => x.A + "-B")
                .Generate(numberOfItems);

            sw.Stop();
            Assert.That(sw.Elapsed.Seconds, Is.LessThan(maxSeconds), string.Format("Generating {0} items with expression setter took {1}", numberOfItems, sw.Elapsed));
        }

        [TestCase(1, 1)]
        [TestCase(100, 1)]
        [TestCase(1000, 1)]
        [TestCase(100000, 3)]
        //[TestCase(100000, 20)]
        //[TestCase(1000000, 180)]
        public void should_quickly_generate_items_with_mappings(int numberOfItems, int maxSeconds)
        {
            var sw = Stopwatch.StartNew();
            new FabricationScope().Setup<AlpabeticalProperties>()
                .For(x => x.B).Map(x => x.A).Using(s => s + "-B")
                .Generate(numberOfItems);

            sw.Stop();
            Assert.That(sw.Elapsed.Seconds, Is.LessThan(maxSeconds), string.Format("Generating {0} items with mapping setter took {1}", numberOfItems, sw.Elapsed));
        }
    }
}
